import Vue from 'vue'
import VueRouter from 'vue-router'
import {
  getToken
} from '@/utils/auth'
Vue.use(VueRouter)

const routes = [{
  path: '/login',
  name: 'home',
  component: () =>
    import(/* webpackChunkName: "about" */ '../views/login/login.vue'),
  meta: {
    name: '登录'
  } //
},
{
  path: '/enroll',
  name: 'enroll',
  component: () =>
    import(/* webpackChunkName: "about" */ '../views/enroll/enroll.vue'),
  meta: {
    name: '注册'
  } //
},
{
  path: '/xieyi',
  name: 'enroll',
  component: () =>
    import(/* webpackChunkName: "about" */ '../views/enroll/components/xiyi.vue'),
  meta: {
    name: '用户协议'
  } //
},
{
  path: '/fenxiao',
  name: 'fenxiao',
  component: () =>
    import(/* webpackChunkName: "about" */ '../views/enroll/components/fenxiao.vue'),
  meta: {
    name: '用户协议'
  } //
},
{
  path: '/wjmm',
  name: 'wjmm',
  component: () =>
    import(/* webpackChunkName: "about" */ '../views/login/wjmm.vue'),
  meta: {
    name: '忘记密码'
  } //
},
{
  path: '/',
  name: 'index',
  component: () =>
    import(/* webpackChunkName: "about" */ '../views/home/parentHome.vue'),
  redirect: '/home',
  meta: {
    name: '首页嵌套'
  },
  children: [{
    path: '/home',
    name: 'home',
    component: () =>
      import(/* webpackChunkName: "about" */ '../views/home/home.vue'),
    meta: {
      name: '首页'
    } //
  },
  {
    path: '/commodity',
    name: 'commodity',
    component: () =>
      import(
        /* webpackChunkName: "about" */
        '../views/commodity/commodity.vue'
      ),
    meta: {
      name: '商品库'
    } //
  },
  {
    path: '/storeQuery',
    name: 'storeQuery',
    component: () =>
      import(
        /* webpackChunkName: "about" */
        '../views/commodity/components/storeQuery.vue'
      ),
    meta: {
      name: '搜索店铺'
    } //
  },
  {
    path: '/integrity',
    name: 'integrity',
    component: () =>
      import(
        /* webpackChunkName: "about" */
        '../views/integrity/integrity.vue'
      ),
    meta: {
      name: '诚信商家'
    }
  },
  {
    path: '/search',
    name: 'search',
    component: () =>
      import(
        /* webpackChunkName: "about" */
        '../views/home/SearchResult.vue'
      ),
    meta: {
      name: '搜索结果'
    } //
  },
  {
    path: '/seasonnew',
    name: 'seasonnew',
    component: () =>
      import(
        /* webpackChunkName: "about" */
        '../views/home/SeasonalNew.vue'
      ),
    meta: {
      name: '当季新品'
    } //
  },
  {
    path: '/seasonselling',
    name: 'seasonselling',
    component: () =>
      import(
        /* webpackChunkName: "about" */
        '../views/home/seasonselling.vue'
      ),
    meta: {
      name: '当季热卖'
    } //
  },
  {
    path: '/live',
    name: 'live',
    component: () =>
      import(
        /* webpackChunkName: "about" */
        '../views/home/live.vue'
      ),
    meta: {
      name: '直播选品'
    } //
  },
  {
    path: '/discount',
    name: 'discount',
    component: () =>
      import(
        /* webpackChunkName: "about" */
        '../views/discount/discount.vue'
      ),
    meta: {
      name: '特价清仓'
    } //
  }
  ]
},
{
  path: '/normalshop',
  name: 'normalshop',
  component: () =>
    import(/* webpackChunkName: "about" */ '../views/shop/normalshop.vue'),
  meta: {
    name: '普通店铺'
  } //
},
{
  path: '/detail',
  name: 'detail',
  component: () =>
    import(/* webpackChunkName: "about" */ '../views/detail/detail.vue'),
  meta: {
    name: '商品详情'
  } //
},
{
  path: '/highshop',
  name: 'highshop',
  component: () =>
    import(/* webpackChunkName: "about" */ '../views/shop/highshop.vue'),
  meta: {
    name: '高级店铺'
  } //
},
{
  path: '/ShoppingCart',
  name: 'ShoppingCart',
  component: () =>
    import(/* webpackChunkName: "about" */ '../views/ShoppingCart'),
  meta: {
    name: '购物车'
  } //
},
{
  path: '/OrderProcess',
  name: 'OrderProcess',
  component: () =>
    import(/* webpackChunkName: "about" */ '../views/BuyerBackOffice/OrderProcess'),
  meta: {
    name: '订单流程'
  } //
},
{
  path: '/PayOrder',
  name: 'PayOrder',
  component: () =>
    import(/* webpackChunkName: "about" */ '../views/BuyerBackOffice/PayOrder'),
  meta: {
    name: '支付订单'
  } //
},
{
  path: '/HelpCenter',
  name: 'HelpCenter',
  component: () =>
    import(/* webpackChunkName: "about" */ '../views/HelpCenter'),
  meta: {
    name: '帮助中心'
  } //
},
{
  path: '/helpDetails',
  name: 'helpDetails',
  component: () =>
    import(/* webpackChunkName: "about" */ '../views/HelpCenter/components/details.vue'),
  meta: {
    name: '帮助中心详情'
  } //
},
{
  path: '/IndividualCenter',
  name: 'IndividualCenter',
  component: () =>
    import(/* webpackChunkName: "about" */ '@/components/IndividualCenter'),
  children: [{
    path: '/BuyerCenter',
    name: 'BuyerCenter',

    component: () => import('@/views/BuyerBackOffice/BuyerCenter'),
    meta: {
      // isNeedLogin: true,
      name: '买家个人中心'
    }
  },
  {
    path: '/MyOrder',
    name: 'MyOrder',

    component: () =>
      import('@/views/BuyerBackOffice/OrderManagement/MyOrder'),
    meta: {
      // isNeedLogin: true,
      name: '买家我的订单'
    }
  },
  {
    path: '/MyOrder',
    name: 'MyOrder',

    component: () =>
      import('@/views/BuyerBackOffice/OrderManagement/MyOrder'),
    meta: {
      // isNeedLogin: true,
      name: '买家我的订单'
    }
  },
  {
    path: '/AfterSaleOrder',
    name: 'AfterSaleOrder',

    component: () =>
      import('@/views/BuyerBackOffice/OrderManagement/AfterSaleOrder'),
    meta: {
      // isNeedLogin: true,
      name: '买家售后订单'
    }
  },
  {
    path: '/applyRefund',
    name: 'applyRefund',

    component: () =>
      import('@/views/BuyerBackOffice/OrderManagement/applyRefund'),
    meta: {
      // isNeedLogin: true,
      name: '申请退款'
    }
  },
  {
    path: '/DownloadRecord',
    name: 'DownloadRecord',

    component: () =>
      import('@/views/BuyerBackOffice/SourceCenter/DownloadRecord'),
    meta: {
      // isNeedLogin: true,
      name: '下载记录'
    }
  },
  {
    path: '/CommodityCollection',
    name: 'CommodityCollection',

    component: () =>
      import('@/views/BuyerBackOffice/MyCollection/CommodityCollection'),
    meta: {
      // isNeedLogin: true,
      name: '商品收藏'
    }
  },
  {
    path: '/StoreCollection',
    name: 'StoreCollection',

    component: () =>
      import('@/views/BuyerBackOffice/MyCollection/StoreCollection'),
    meta: {
      // isNeedLogin: true,
      name: '店铺收藏'
    }
  },
  {
    path: '/PersonalData',
    name: 'PersonalData',

    component: () =>
      import('@/views/BuyerBackOffice/PersonalData'),
    meta: {
      // isNeedLogin: true,
      name: '个人资料'
    }
  },
  {
    path: '/editData',
    name: 'editData',

    component: () =>
      import('@/views/BuyerBackOffice/PersonalData/components/editData'),
    meta: {
      // isNeedLogin: true,
      name: '编辑资料'
    }
  },
  {
    path: '/SupplierPlacement',
    name: 'SupplierPlacement',

    component: () =>
      import('@/views/BuyerBackOffice/SupplierPlacement'),
    meta: {
      // isNeedLogin: true,
      name: '供应商入驻'
    }
  },
  {
    path: '/sellerCenter',
    name: 'sellerCenter',

    component: () => import('@/views/sellerBackOffice/SellerCenter'),
    meta: {
      // isNeedLogin: true,
      name: '卖家个人中心'
    }
  },
  {
    path: '/CommodityCategory',
    name: 'CommodityCategory',

    component: () => import('@/views/sellerBackOffice/management/components/CommodityCategory.vue'),
    meta: {
      // isNeedLogin: true,
      name: '商品管理'
    }
  },
  {
    path: '/management',
    name: 'management',

    component: () => import('@/views/sellerBackOffice/management/management.vue'),
    meta: {
      // isNeedLogin: true,
      name: '商品管理'
    }
  },
  {
    path: '/cangpushop',
    name: 'cangpushop',

    component: () => import('@/views/sellerBackOffice/cangpushop/cangpushop.vue'),
    meta: {
      // isNeedLogin: true,
      name: '店铺商品'
    }
  },
  {
    path: '/ClearanceGoods',
    name: 'ClearanceGoods',

    component: () => import('@/views/sellerBackOffice/ClearanceGoods'),
    meta: {
      // isNeedLogin: true,
      name: '清仓商品'
    }
  },
  {
    path: '/LiveSelection',
    name: 'LiveSelection',

    component: () => import('@/views/sellerBackOffice/LiveSelection'),
    meta: {
      // isNeedLogin: true,
      name: '直播选品'
    }
  },
  {
    path: '/adentry',
    name: 'adentry',
    component: () => import('@/views/sellerBackOffice/adentry'),
    meta: {
      isNeedLogin: true,
      name: '广告报名'
    }
  },
  {
    path: '/MyAD',
    name: 'MyAD',
    component: () => import('@/views/sellerBackOffice/MyAD'),
    meta: {
      isNeedLogin: true,
      name: '我的广告'
    }
  },
  {
    path: '/adDetails',
    name: 'adDetails',
    component: () => import('@/views/sellerBackOffice/MyAD/components/adDetails.vue'),
    meta: {
      isNeedLogin: true,
      name: '广告详情'
    }
  },
  {
    path: '/mypayment',
    name: 'mypayment',
    component: () => import('@/views/sellerBackOffice/mypayment'),
    meta: {
      isNeedLogin: true,
      name: '我的货款'
    }
  },
  {
    path: '/myaccount',
    name: 'myaccount',
    component: () => import('@/views/sellerBackOffice/myaccount'),
    meta: {
      isNeedLogin: true,
      name: '我的账户'
    }
  },
  {
    path: '/paysafe',
    name: 'paysafe',
    component: () => import('@/views/sellerBackOffice/paysafe'),
    meta: {
      isNeedLogin: true,
      name: '资产安全'
    }
  },
  {
    path: '/bind',
    name: 'bind',
    component: () => import('@/views/sellerBackOffice/paysafe/bind.vue'),
    meta: {
      isNeedLogin: true,
      name: '绑定账户'
    }
  },
  {
    path: '/shopMange',
    name: 'shopMange',
    component: () => import('@/views/sellerBackOffice/shopMange'),
    meta: {
      isNeedLogin: true,
      name: '店铺管理'
    }
  },
  {
    path: '/editStore',
    name: 'editStore',
    component: () => import('@/views/sellerBackOffice/shopMange/components/editStore.vue'),
    meta: {
      isNeedLogin: true,
      name: '编辑店铺信息'
    }
  },
  {
    path: '/authentication',
    name: 'authentication',
    component: () => import('@/views/sellerBackOffice/shopMange/components/authentication.vue'),
    meta: {
      isNeedLogin: true,
      name: '实名认证'
    }
  },
  {
    path: '/FunctionalInterest',
    name: 'FunctionalInterest',
    component: () => import('@/views/sellerBackOffice/FunctionalInterest'),
    meta: {
      isNeedLogin: true,
      name: '功能权益'
    }
  }
  ]
}
]

const router = new VueRouter({
  routes,
  base: process.env.BASE_URL
})
router.beforeEach((to, from, next) => {
  // 1获取路由的元数据信息
  const {
    isNeedLogin
  } = to.meta
  // 取出登录成功之后保存的登录凭证
  const token = getToken()
  // 2判断哪些页面需要进行登录判断
  if (isNeedLogin) {
    // 证明页面需要进行登录
    if (!token) {
      // next(`/`);
      next()
    } else {
      // 证明登陆过了
      next()
    }
  } else {
    // 证明页面不需要登录
    next() // 继续跳转到对应的页面
  }
})

export default router
